package com.istock.union.user.filter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.util.StringUtils;
import org.springframework.web.method.HandlerMethod;

import com.istock.union.user.utils.WebCommonUtils;

public abstract class AuthorizationCallbackAdapter implements AuthorizationCallback {

	/**
	 * AuthorizationInterceptor拦截器的执行,url匹配是在spring配置的
	 * 这边配置的是排除,允许在AuthorizationInterceptor配置的基础上,配置排除策略
	 */
	private String ignorRegx;
	public void setIgnorRegx(String ignorRegx) {
		this.ignorRegx = ignorRegx;
	}
	
	@Override
	public boolean canExecut(HttpServletRequest request, HandlerMethod targetObj) {
		if(StringUtils.hasLength(ignorRegx)) {
			String url = WebCommonUtils.findAccessPath(request);
			return !url.matches(ignorRegx);
		}
		return true;
	}

	@Override
	public boolean preCallback(HttpServletRequest request, HttpServletResponse response, HandlerMethod targetObj) {
		return true;
	}

	@Override
	public boolean postCallback(HttpServletRequest request, HttpServletResponse response, HandlerMethod targetObj) {
		return true;
	}

}
